/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package customer_jdom;

import entities.Account;
import java.io.PrintStream;
import java.util.List;

import org.jdom2.Element;
import org.jdom2.output.XMLOutputter;

/**
 *
 * eCOM - Adopte un Presta - Mars-Avril 2013
 * @author Kheira, Jef, William, Tuan-Long
 */
public class AccountJDOM extends AbstractJDOM<Account> {

    public AccountJDOM() 
    {
        // Vide.
    }
    
    @Override
    public void print(PrintStream out, List<Account> accounts) {
        out.printf("%7s   %-20s   %6s%n", "ID", "IBAN", "BALANCE");
        out.printf("--------------------------------------------------------%n");
        for (Account a : accounts) {
            String id = a.getIdAccount().toString();
            String iban = a.getIban();
            String solde = a.getSolde().toString();
            out.printf("%7s   %-20s   %6s%n", id, iban, solde);
        }
        out.println();
    }


    @Override
    public Element getXmlRepresentation(Account account){
        Element element = new Element("account");
        Element id = new Element("id");
        id.setText(String.valueOf(account.getIdAccount()));
        Element iban = new Element("iban");
        iban.setText(account.getIban());
        Element solde = new Element("solde");
        solde.setText(account.getSolde().toString());
        
        
        element.addContent(id);
        element.addContent(iban);
        element.addContent(solde);
        return element;
    }

    @Override
    public String getClassName(){
        return "account";
    }    
}

